import math
q=str(input())
e=int(q)
t=0
if len(q)!=4 or e<0:
    print(0)
f=q[0]
r=int(f)
for w in range(2,int(r**0.5)+1):
    if r%w==0:
        break
else:
    t=r
f=q[1]
r=int(f)
for w in range(2,int(r**0.5)+1):
    if r%w==0:
        break
else:
    y=r
    if y>t:
        t=y
f=q[2]
r=int(f)
for w in range(2,int(r**0.5)+1):
    if r%w==0:
        break
else:
    u=r
    if u>t:
        t=u
f=q[3]
r=int(f)
for w in range(2,int(r**0.5)+1):
    if r%w==0:
        break
else:
    i=r
    if i>t:
        t=i
f=q[0]+q[1]
r=int(f)
for w in range(2,int(r**0.5)+1):
    if r%w==0:
        break
else:
    o=r
    if o>t:
        t=o
f=q[0]+q[1]+q[2]
r=int(f)
for w in range(2,int(r**0.5)+1):
    if r%w==0:
        break
else:
    p=r
    if p>t:
        t=p
f=q[1]+q[2]
r=int(f)
for w in range(2,int(r**0.5)+1):
    if r%w==0:
        break
else:
    a=r
    if a>t:
        t=a
f=q[1]+q[2]+q[3]
r=int(f)
for w in range(2,int(r**0.5)+1):
    if r%w==0:
        break
else:
    s=r
    if s>t:
        t=s
f=q[2]+q[3]
r=int(f)
for w in range(2,int(r**0.5)+1):
    if r%w==0:
        break
else:
    d=r
    if d>t:
        t=d


for w in range(2,int(e**0.5)+1):
    if e%w==0:
        break
else:
    x=e
    if x>t:
        t=x
if t==0:
    print(0)
else:
    print(t)